package com.ruoyi.produce.process.productionLine.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.produce.process.productionLine.domain.ProductionLineCond;
import com.ruoyi.produce.process.productionLine.domain.ProductionLineDomain;
import com.ruoyi.produce.process.productionLine.domain.ProductionLineDto;
import com.ruoyi.produce.process.productionLine.service.IProductionLineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制层
 */
@RestController
@RequestMapping("/produce/productionLine")
@Api(value = "产线模块", tags = "产线接口")
public class ProductionLineController extends BaseController {
    @Autowired
    private IProductionLineService productionLineService;

    /**
     * 获取产线列表
     * @return
     */
    @ApiOperationSupport(includeParameters = {"ProductionLineCond.workSheetId", "ProductionLineCond.actuallyStartTime"})
    @ApiOperation(value = "获取产线列表",notes = "查询所有产线信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ProductionLineCond cond) {
        startPage();
        List<ProductionLineDto> productionLineDtos = productionLineService.selectProductionLineList(cond);
        return getDataTable(productionLineDtos);
    }

    /**
     * 根据编号获取详细信息
     */
    @GetMapping(value = "/{productionLineId}")
    @ApiOperation(value = "根据编号获取详细信息",notes = "根据编号获取详细信息")
    public AjaxResult getInfo(@PathVariable int productionLineId)
    {
        return AjaxResult.success(productionLineService.selectProductionLineById(productionLineId));
    }

    /**
     * 新增产线
     * @param productionLine
     * @return
     */
    @ApiOperation(value = "新增产线记录", notes = "新增产线信息")
    @ApiImplicitParam(name = "productionLine", value = "新增产线记录", dataType = "ProductionLineDomain")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ProductionLineDomain productionLine) {
        return toAjax(productionLineService.insertProductionLine(productionLine));
    }

    /**
     * 修改产线记录
     * @param productionLine
     * @return
     */
    @ApiOperation(value = "修改产线记录", notes = "修改产线信息")
    @ApiImplicitParam(name = "productionLine", value = "修改产线记录", dataType = "ProductionLineDomain")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ProductionLineDomain productionLine) {
        return toAjax(productionLineService.updateProductionLine(productionLine));
    }

    /**
     * 删除产线记录
     * 仅修改删除标志位
     * @param productionLine
     * @return
     */
    @ApiOperation(value = "删除产线记录", notes = "删除产线记录,仅删除标志位")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody ProductionLineDomain productionLine) {
        return toAjax(productionLineService.updateProductionLineDeleteFlag(productionLine));
    }
}
